<template>
  <div>
    <nav-bar>
      <div slot="title">{{titleName}}</div>
    </nav-bar>
     <scroll class="scroll" ref="scroll" :pullUpLoad="true" :probe-type="3">
       <goods-list :button="true" :goodsData="showGoods"><button slot="button">删除</button></goods-list>
     </scroll>
  </div>
</template>

<script>
  import goodsList from 'components/content/Goods/goodsList'
  import scroll from 'components/common/scroll/scroll.vue'
  import {getAllLike,deleteLike} from 'network/like/like.js'
  import navBar from './components/navBar.vue'

  export default{
    name:'',
    data(){
      return {
          showGoods:[],
          titleName:"我的收藏"
       }
    },
    methods:{
      getAllGood(){
        let userId=JSON.parse(window.sessionStorage.user).id
        getAllLike(userId).then(res=>{
          this.showGoods=res.data.list
          let g=this.showGood
          for(let i of this.showGoods){
            i.cfav=i.num
          }
          // console.log("show",JSON.stringify(this.showGoods));
          window.sessionStorage.setItem('likeGood',JSON.stringify(this.showGoods))

        }).catch(e=>{
          console.log(e);
        })
      }
    },
    components:{
       goodsList,navBar,scroll
    },
    activated() {
      this.getAllGood()
    },
    mounted() {
      this.$bus.$on('deleteGood',res=>{
        console.log(res);
        let userId=JSON.parse(window.sessionStorage.user).id
        deleteLike(userId,res).then(res=>{
          console.log(res);
          this.getAllGood()
        }).catch(e=>{
          console.log(e);
        })
      })
    }
  }
</script>

<style scoped>
 .scroll{
    height: calc(100% - 93px);
    overflow: hidden;
    position: absolute;
    top: 44px;
    bottom: 49px;
    left: 0;
    right: 0;
  }
</style>
